﻿<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>jQuery子元素过滤器:nth-child示例</title>
        <script src="js/jquery-3.6.1.min.js"></script>
		<style>
		ul{
			width:150px;
			border:1px solid;
			float:left;
			margin:10px;
		}
		</style>
    </head>
    <body>
        <h3>jQuery子元素过滤器:nth-child示例</h3>
        <hr>
		<ul id="item01">
		li:nth-child(odd)
		筛选奇数项
		    <li>Apple</li>
		    <li>Pear</li>
		    <li>Grape</li>
			<li>Pineapple</li>
		</ul>
		<ul id="item02">
		li:nth-child(2)
		筛选第二个元素
		    <li>Milk</li>
		    <li>Bread</li>
		    <li>Coffee</li>
		</ul>
		<ul id="item03">
		li:nth-child(3n+2)
		筛选第3n+2个元素
		    <li>Red</li>
		    <li>Blue</li>
		    <li>Green</li>
			<li>Yellow</li>
		    <li>Orange</li>
		    <li>Purple</li>
		</ul>
        <script>
            $(document).ready(function() {
				//选择奇数项子元素
                $("ul#item01 li:nth-child(odd)").css("color","red");
				//选择第二个子元素
				$("ul#item02 li:nth-child(2)").css("color","red");
				//选择第3n+2个子元素
				$("ul#item03 li:nth-child(3n+2)").css("color","red");
            });
        </script>
    </body>
</html>